from django.shortcuts import render, HttpResponse
import datetime
import requests
from django.http import JsonResponse
from django.core import serializers

# Create your views here.
from hero.models import SqlliteDota2Hero

class Hero(object):

    def __init__(self, name,head_image):
        self.name = name
        self.head_image = head_image

    def __str__(self):
        return self.name


def index(request):
    now = datetime.datetime.now().strftime("%Y-%m-%d %X")
    heroes = SqlliteDota2Hero.objects.all().values("name","head_image")


    hero_list = []
    for hero in heroes:
        hero_list.append(Hero(hero["name"],hero["head_image"]))


    return render(request, "index.html", {"hero_list":hero_list})


def hero(request):
    now = datetime.datetime.now().strftime("%Y-%m-%d %X")
    users = SqlliteDota2Hero.objects.all()
    for hero in users:
        print(hero.name)

    return render(request, "index.html", {"now": now})


def first(request):
    now = datetime.datetime.now().strftime("%Y-%m-%d %X")
    users = SqlliteDota2Hero.objects.first()
    print(users.name)
    return render(request, "index.html", {"now": now})


def last(request):
    now = datetime.datetime.now().strftime("%Y-%m-%d %X")
    users = SqlliteDota2Hero.objects.last()
    print(users.name)
    return render(request, "index.html", {"now": now})


def distance(request):
    now = datetime.datetime.now().strftime("%Y-%m-%d %X")
    users = SqlliteDota2Hero.objects.filter(attackcapabilities="近战")
    for hero in users:
        print(hero.name)
    return render(request, "index.html", {"now": now})

